﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Scheduling.Models
{
    /// <summary>
    /// Manages the used session variables. 
    /// Provides encapsulation around TDD functions. 
    /// </summary>
    public class SessionManager
    {
        /// <summary>
        /// The current User ID. 
        /// </summary>
        public static string UserID { 
            get { return GetSession("UserID"); }
            set { SetSession("UserID", value); }
        }

        /// <summary>
        /// The current User Group ID. 
        /// </summary>
        public static string UserGroupID {
            get { return GetSession("UserGroupID"); }
            set { SetSession("UserGroupID", value); }
        }

        /// <summary>
        /// The current User Group Name. 
        /// </summary>
        public static string UserGroupName {
            get { return GetSession("UserGroupName"); }
            set { SetSession("UserGroupName", value); }
        }

        /// <summary>
        /// Returns the value of a specific session variable. 
        /// </summary>
        /// <param name="SessionKey">Name of the session variable. </param>
        /// <returns>Value of the session variable. </returns>
        private static string GetSession(string SessionKey)
        {
            if (HttpContext.Current == null) 
                return string.Empty;
            var sessionValue = HttpContext.Current.Session[SessionKey];
            if (sessionValue != null)
                return sessionValue as string;
            else
                return null;
        }

        /// <summary>
        /// Sets a session variable to the specified value. 
        /// </summary>
        /// <param name="SessionKey">Name of the session variable. </param>
        /// <param name="SessionValue">The value the session variable will be set to. </param>
        private static void SetSession(string SessionKey, string SessionValue)
        {
            if (HttpContext.Current == null) HttpContext.Current.Session[SessionKey] = SessionValue;
        }
    }
}